<!DOCTYPE html>
<html>
    <head>
        <meta charset="UTF-8">
        <title>自定义事件</title> 
    </head>
    <body>
        <div id = "app">
            <p>总数：{{ total }}</p>
            <!--
            这边的v-model相当于绑定了子组件的counter
            input特殊事件名的作用
            -->
            <my-component v-model ="total"></my-component>
        </div>
        <script src = "../../vue.min.js"></script>
        <script>
            Vue.component('my-component',{
                template:'<button @click="handleClick">+1</button>',
                data: function(){
                    return {
                        counter:0
                    }
                },
                methods:{
                    handleClick() {
                        this.counter++;
                        this.$emit('input', this.counter);
                    }
                }
            });
            var app = new Vue({
                el: '#app',
                data:{
                    total:0
                }
            })
        </script>
    </body>
</html>